

using UnityEngine;
using Cesium3DTilesSelection;
using System;
using System.Collections;
using System.Linq;
public class CesiumRasterOverlay : MonoBehaviour
{
    public string MaterialLayerKey = "Overlay0";

    private RasterOverlay pOverlay;

    IEnumerator Start()
    {
        yield return new WaitForEndOfFrame();
        AddToTileset();
    }
    public void AddToTileset()
    {
        if (this.pOverlay)
        {
            return;
        }
        var mTileset = GetComponent<Cesium3DTileset>();
        if (mTileset == null) return;

        var pTIleset = mTileset.pTileset;
        this.pOverlay = this.CreateOverlay();
        pTIleset.Overlays.Add(this.pOverlay);
    }

    public void RemoveFromTileset()
    {
        if (!this.pOverlay)
        {
            return;
        }
        var mTileset = GetComponent<Cesium3DTileset>();
        if (mTileset == null) return;
        var pTIleset = mTileset.pTileset;

        pTIleset.Overlays.Remove(this.pOverlay);
        this.pOverlay = null;
    }

    protected virtual RasterOverlay CreateOverlay()
    {
        return null;
    }

    protected virtual void OnAdd(Tileset pTileset, RasterOverlay pOverlay)
    {

    }

    protected virtual void OnRemove(Tileset pTileset, RasterOverlay pOverlay)
    {

    }
}